﻿package com.athena.controller 
{
	import com.athena.vo.ObjectTable;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.text.TextFormat;
	import com.athena.process.ProcessOutTable_Frame2;

	/**
	 * ...
	 * @author Tamnt
	 */
	public class TableController 
	{
		var m_movie_mc:MovieClip;
		var objT:ObjectTable;
		public static function numberFormat(number:Number, maxDecimals:int = 2, forceDecimals:Boolean = false, siStyle:Boolean = true):String {
			var i:int = 0, inc:Number = Math.pow(10, maxDecimals), str:String = String(Math.round(inc * Number(number))/inc);
			var hasSep:Boolean = str.indexOf(",") == -1, sep:int = hasSep ? str.length : str.indexOf(",");
			var ret:String = (hasSep && !forceDecimals ? "" : (siStyle ? "." : ",")) + str.substr(sep+1);
			if (forceDecimals) for (var j:int = 0; j <= maxDecimals - (str.length - (hasSep ? sep-1 : sep)); j++) ret += "0";
			while (i + 3 < (str.substr(0, 1) == "-" ? sep-1 : sep)) ret = (siStyle ? "," : ".") + str.substr(sep - (i += 3), 3) + ret;
			return str.substr(0, sep - i) + ret;
		}
		public function TableController(_mc:MovieClip,_obj:ObjectTable, arrName : Array) 
		{
			m_movie_mc = _mc ;
			//Cotuong.tf.appendText("=>11") ;
			m_movie_mc.header_txt.text = _obj.TableName + ": " + numberFormat( _obj.MarkUnit, 0, false, true);
			m_movie_mc.user0_txt.text = "" ;
			m_movie_mc.user1_txt.text = "" ;
			//Cotuong.tf.appendText("=>22") ;
			var formatText : TextFormat = new TextFormat() ;				
			formatText.font = "Tahoma" ;
			formatText.bold = false ;
			formatText.size = 12 ;
			m_movie_mc.header_txt.setTextFormat(formatText) ;	
			//Cotuong.tf.appendText("=>33") ;
			for (var l:int = 0; l < arrName.length; l++) 
			{
				if (l == 0)
					m_movie_mc.user0_txt.text = arrName[l] ;
				else if (l == 1)
					m_movie_mc.user1_txt.text = arrName[l] ;
			}
			objT = _obj;
			//Cotuong.tf.appendText("=>44") ;
			m_movie_mc.addEventListener(MouseEvent.MOUSE_OVER, movie_mc_over);
			m_movie_mc.addEventListener(MouseEvent.MOUSE_OUT, movie_mc_out);
			m_movie_mc.addEventListener(MouseEvent.CLICK, movie_mc_click);
		}
		function movie_mc_over(evt:MouseEvent)
		{
			
		}
		
		function movie_mc_out(evt:MouseEvent)
		{
			
		}		

		function movie_mc_click(evt:MouseEvent)
		{
			ProcessOutTable_Frame2.clickJoinTable(objT.TableID);
		}
	}

}